<?php

function list_paket(){
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Gol'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Paket MCU'=>array('style'=>'border-bottom:2px solid;width:75%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	$query = "SELECT a.*,b.label_paket FROM golongan_jabatan a 
		LEFT JOIN paket_mcu b ON a.golongan_jabatan_id=b.golongan_jabatan_id 
		ORDER BY a.golongan_jabatan_id ASC";
	$result = my_query($query);
	$i=0;
	$row = array();
	while($ey = my_fetch_array($result) ){
		$i++;
		$editproperty = array(
			'href'=>'index.php?com=paket_mcu&task=edit&id='.$ey['golongan_jabatan_id'] ,
			'title'=>'Edit',
			'rel'=>'facebox'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$row[] = array(
			'#'=>position_text_align ($i, 'center'),    
			'gol'=>  $ey['kode_golongan_jabatan'] ,     
			'label'=>  $ey['label_paket'],
			'operasi'=> position_text_align( $edit_button , 'right'),
		);
	}
	$datas = table_rows($row); 
	return  $view.'<br/>'. table_builder($header , $datas ,  5 , false );
}
function form_paket($id){
  	
	$view = form_header( "paket_mcu" , "paket_mcu"  );
 	$fields = my_get_data_by_id('paket_mcu','golongan_jabatan_id',$id); 
	$golongan_jabatan = my_get_data_by_id('golongan_jabatan','golongan_jabatan_id',$id);
	$view .= form_field_display( $golongan_jabatan['kode_golongan_jabatan'], " Golongan");
	$temp = array(
		'name'=>'label_paket',
		'value'=>( isset($_POST['label_paket']) ? $_POST['label_paket'] :$fields['label_paket'] ),
		'id'=>'label_paket',
		'type'=>'text',
		'size'=>'15'
	);
	$form_temp = form_dynamic($temp); 
	$view .= form_field_display( $form_temp   , "Paket MCU"   );

	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}


function validate_paket($id){
	$errsubmit = false;
	$err = array();
 /*   
	if(! is_numeric(trim($_POST['sumber']) )){
		$errsubmit = true;
		$err[] = "Data sumber bukan angka";
	}
	if(! is_numeric(trim($_POST['pendukung']) )){
		$errsubmit = true;
		$err[] = "Data pendukung bukan angka";
	}
 */

	if( $errsubmit){
		return $err;
	} 
	return $errsubmit;
}

function submit_paket($id = 0){
	$pakets=my_get_data_by_id('paket_mcu','golongan_jabatan_id',$id);
	$datas = array(
		'golongan_jabatan_id'=>my_type_data_int($id), 		 	 	 	 	 	 	 
		'label_paket'=>my_type_data_str($_POST['label_paket']), 		 	 	 	 	 	 	 
	);
	if($pakets){
		return my_update_record('paket_mcu','golongan_jabatan_id',$id, $datas);
	}
	return my_insert_record('paket_mcu' , $datas);
}
